package planesimulator.plane;

import com.jme.math.*;

/**
 * Some basic mathematical functions used in game.
 * @author Jakub Klimek
 */
public class PlaneMath {

  /** Vector outer product */
  public static void vectoutprod(Vector3f v1, Vector3f v2, Vector3f v3) {
    Vector3f res = new Vector3f();

    res.x = v1.y * v2.z - v1.z * v2.y;
    res.y = v1.z * v2.x - v1.x * v2.z;
    res.z = v1.x * v2.y - v1.y * v2.x;

    v3.x = res.x;
    v3.y = res.y;
    v3.z = res.z;
  }

  /** Quaternion product */
  public static void quatprod(Quaternion q1, Quaternion q2, Quaternion q3) {
    Quaternion r = new Quaternion();

    r.w = q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z;
    r.x = q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y;
    r.y = q1.w * q2.y + q1.y * q2.w + q1.z * q2.x - q1.x * q2.z;
    r.z = q1.w * q2.z + q1.z * q2.w + q1.x * q2.y - q1.y * q2.x;

    q3.w = r.w;
    q3.x = r.x;
    q3.y = r.y;
    q3.z = r.z;
  }

  /** Class that prints out roration when given angles */
  public static void printRotation(Vector3f q) {
    System.out.println("heading : " + Math.toDegrees(q.y) +
        " pitch " + Math.toDegrees(q.z) + " roll " +
        Math.toDegrees(q.x));
  }

  /** Class that prints out roration when given quaternion */
  public static void printRotation(Quaternion q) {
    float[] angles = new float[3];
    q.toAngles(angles);
    System.out.println("heading : " + Math.toDegrees(angles[1]) +
        " pitch " + Math.toDegrees(angles[2]) + " roll " +
        Math.toDegrees(angles[0]));
  }
}
